//
//  TableView.m
//  MNHire
//
//  Created by lxy on 2017/5/4.
//  Copyright © 2017年 Shanghai Chengtai. All rights reserved.
//

#import "TableView.h"

@implementation TableView

- (instancetype)init {
    
    if (self = [super init]) {
        self.delaysContentTouches = NO;
        self.backgroundColor= [UIColor clearColor];
        //针对ios8及以上系统，以为ios8及以上系统，UITableView与UITableViewCell之间为UITableViewWrapperView(UIScrollView)
        for (id obj in self.subviews) {
            if ([NSStringFromClass([obj class]) isEqualToString:@"UITableViewWrapperView"]) {
                if ([obj isKindOfClass:[UIScrollView class]]) {
                    UIScrollView *scroll = (UIScrollView *)obj;
                    scroll.delaysContentTouches = NO;
                    
                }
                break;
            }
        }
        
        if (@available(iOS 11.0, *)) {
            self.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
            self.estimatedRowHeight = 0;
            self.estimatedSectionHeaderHeight = 0;
            self.estimatedSectionFooterHeight = 0;
        }
    }
    return self;
}

- (instancetype)initWithFrame:(CGRect)frame {
    if (self = [super initWithFrame:frame]) {
        self.delaysContentTouches = NO;
        self.backgroundColor= [UIColor clearColor];
        //针对ios8及以上系统，以为ios8及以上系统，UITableView与UITableViewCell之间为UITableViewWrapperView(UIScrollView)
        for (id obj in self.subviews) {
            if ([NSStringFromClass([obj class]) isEqualToString:@"UITableViewWrapperView"]) {
                if ([obj isKindOfClass:[UIScrollView class]]) {
                    UIScrollView *scroll = (UIScrollView *)obj;
                    scroll.delaysContentTouches = NO;
                    
                }
                break;
            }
        }
        
        if (@available(iOS 11.0, *)) {
            self.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
            self.estimatedRowHeight = 0;
            self.estimatedSectionHeaderHeight = 0;
            self.estimatedSectionFooterHeight = 0;
        }
    }
    return self;
}


-(instancetype)initWithFrame:(CGRect)frame style:(UITableViewStyle)style{
    
    if (self = [super initWithFrame:frame style:style]) {
        self.delaysContentTouches = NO;
        self.backgroundColor= [UIColor clearColor];
        //针对ios8及以上系统，以为ios8及以上系统，UITableView与UITableViewCell之间为UITableViewWrapperView(UIScrollView)
        for (id obj in self.subviews) {
            if ([NSStringFromClass([obj class]) isEqualToString:@"UITableViewWrapperView"]) {
                if ([obj isKindOfClass:[UIScrollView class]]) {
                    UIScrollView *scroll = (UIScrollView *)obj;
                    scroll.delaysContentTouches = NO;
                    
                }
                break;
            }
        }
        
        if (@available(iOS 11.0, *)) {
            self.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
            self.estimatedRowHeight = 0;
            self.estimatedSectionHeaderHeight = 0;
            self.estimatedSectionFooterHeight = 0;
        }
    }
    return self;
}

/*即使触摸到的是一个 UIControl (如子类：UIButton), 我们也希望拖动时能取消掉动作以便响应滚动动作*/
- (BOOL)touchesShouldCancelInContentView:(UIView *)view{
    
    if ([view isKindOfClass:[UIControl class]]) {
        return YES;
    }
    
    return [super touchesShouldCancelInContentView:view];
}


- (BOOL)touchesShouldBegin:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event inContentView:(UIView *)view {
    if ([view isKindOfClass:[UIControl class]]) {
        return YES;
    }
    
    return [super touchesShouldBegin:touches withEvent:event inContentView:view];
}


@end
